<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="text" />
	<xsl:template match="/">
<xsl:value-of select="Schema/@UsingNamespace" />

	/// <summary>
	/// 编辑<xsl:value-of select="Schema/@TableName" />
	///	</summary>
	public partial class <xsl:value-of select="Schema/@TableName" />Edit : <xsl:value-of select="Schema/@BasePageClass" />
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    LanguageSelect.LanguageChanged += new LanguageChangeHandler(this.LanguageChanged);
    if (!IsPostBack)
    {
    //判断权限
    //if (!CheckRight("FinanceOrderAdmin"))
    //{
    //	NoRightAlert();
    //}
    }

    if (!IsPostBack)
    {
    // 初始化语言下拉框
    LanguageSelect.InitLanguageData();
    // 获取语言参数，并赋给控件。
    string strLanguageID = (string)QueryTable["LanguageID"];
    if (strLanguageID != null <xsl:text disable-output-escaping="yes">&amp;</xsl:text><xsl:text disable-output-escaping="yes">&amp;</xsl:text> strLanguageID != "")
    LanguageSelect.LanguageID = strLanguageID;

    LanguageID = LanguageSelect.LanguageID;

    string strAction = (string)QueryTable["Action"];
    ViewState["Action"] = strAction;
    if (strAction == "edit")
    {
    //加载数据
    int int<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each> = int.Parse((string)QueryTable["<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>"]);
					ViewState["<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>"] = int<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>;

                    <xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = <xsl:value-of select="Schema/@TableName" />Biz.Get<xsl:value-of select="Schema/@TableName" />(LanguageID,int<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>);
					<xsl:for-each select="Schema/Columns[IsIdentity='false']">
					txt<xsl:value-of select="ColumnName"></xsl:value-of>.Text = obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="ColumnName"></xsl:value-of>.ToString();
					</xsl:for-each>
				}
				else
				{
					ViewState["<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>"] = 0;
    }
    }

    }

    /// <summary>
    /// 当语言变化时，把语言编号保存在ViewState中
    ///</summary>
    private void LanguageChanged(object sender, System.EventArgs e)
    {
    Response.Redirect("<xsl:value-of select="Schema/@TableName" />Edit.aspx?" + GetEncryptQueryString("LanguageID=" + LanguageSelect.LanguageID + "<xsl:text disable-output-escaping="yes">&amp;</xsl:text>Action=" + (string)ViewState["Action"] + "<xsl:text disable-output-escaping="yes">&amp;</xsl:text><xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>=" + (string)ViewState["<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>"] ));
    }

    protected void btnOK_Click(object sender, System.EventArgs e)
    {
      if ((string)ViewState["Action"] == "add")
      {
          <xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = new <xsl:value-of select="Schema/@TableName" />();
					//TODO:根据字段类型将输入控件的值赋予实体相应的属性
					<xsl:for-each select="Schema/Columns[IsIdentity='false']">
					//obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="ColumnName"></xsl:value-of>= txt<xsl:value-of select="ColumnName"></xsl:value-of>.Text;
					</xsl:for-each>
          try
          {
					  <xsl:value-of select="Schema/@TableName" />Biz.Add<xsl:value-of select="Schema/@TableName" />(LanguageID,obj<xsl:value-of select="Schema/@TableName" />);
			    }
			    catch (Exception ex)
			    {
				    lblMessage.Text = "操作失败，<br />" + ex.Message;
            return;
			    }

					ShowServerMessage("添加成功", "<xsl:value-of select="Schema/@TableName" />" + obj<xsl:value-of select="Schema/@TableName" />.<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>.ToString() + "添加成功！", "<xsl:value-of select="Schema/@TableName" />List.aspx");
			}
			else if ((string)ViewState["Action"] == "edit")
			{
          <xsl:value-of select="Schema/@TableName" /> obj<xsl:value-of select="Schema/@TableName" /> = <xsl:value-of select="Schema/@TableName" />Biz.Get<xsl:value-of select="Schema/@TableName" />((int)ViewState["<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>"]);
					//TODO:根据字段类型将输入控件的值赋予实体相应的属性
					<xsl:for-each select="Schema/Columns[IsIdentity='false']">
					//obj<xsl:value-of select="/Schema/@TableName" />.<xsl:value-of select="ColumnName"></xsl:value-of>= txt<xsl:value-of select="ColumnName"></xsl:value-of>.Text;
					</xsl:for-each>

          try
          {
					  <xsl:value-of select="Schema/@TableName" />Biz.Update<xsl:value-of select="Schema/@TableName" />(LanguageID,obj<xsl:value-of select="Schema/@TableName" />);
			    }
			    catch (Exception ex)
			    {
				    lblMessage.Text = "操作失败，<br />" + ex.Message;
            return;
			    }

					ShowServerMessage("修改成功", "<xsl:value-of select="Schema/@TableName" />" + obj<xsl:value-of select="Schema/@TableName" />.<xsl:for-each select="Schema/Columns[IsPK='1']"><xsl:value-of select="ColumnName" /></xsl:for-each>.ToString() + "修改成功！", "<xsl:value-of select="Schema/@TableName" />List.aspx");
			}
	 }
}
	</xsl:template>
</xsl:stylesheet>